package vip.idiy.anwei_android_iot.utils;



import java.lang.ref.WeakReference;

import vip.idiy.anwei_android_iot.DeviceHandleActivity;
import vip.idiy.anwei_android_iot.MainActivity;
import vip.idiy.anwei_android_iot.SceneHandleActivity;
import vip.idiy.anwei_android_iot.TypeHandleActivity;

/**
 * ClassName ActivityFactory
 * describe: Activity间调用函数
 * Created: 勇
 * Email:118085890@qq.com
 * Version: 1.0
 * Create in 14:50 2023/4/21
 */
public class ActivityFactory {
    public static WeakReference<SceneHandleActivity> sceneHandleActivityRef;
    public static WeakReference<TypeHandleActivity> typeHandleActivityWeakRef;
    public static WeakReference<MainActivity> mainActivityWeakRef;
    public static WeakReference<DeviceHandleActivity> deviceHandleActivityRef;

    public static void setSceneHandleActivity(SceneHandleActivity activity) {
        sceneHandleActivityRef = new WeakReference<>(activity);
    }
    public static void sceneHandleActivity_flushList(int mode) {
        if (sceneHandleActivityRef != null) {
            SceneHandleActivity activity = sceneHandleActivityRef.get();
            if (activity != null) {
                activity.flushList(mode);
            }
        }
    }


    public static void setTypeHandleActivity(TypeHandleActivity activity){
        typeHandleActivityWeakRef = new WeakReference<>(activity);
    }
    public static void typeHandleActivity_flushList(int mode) {
        if (typeHandleActivityWeakRef != null) {
            TypeHandleActivity activity = typeHandleActivityWeakRef.get();
            if (activity != null) {
                activity.flushList(mode);
            }
        }
    }

    public static void setMainActivity(MainActivity activity){
        mainActivityWeakRef = new WeakReference<>(activity);
    }

    public static void mainActivity_defaultSelectHome(){
        if(mainActivityWeakRef!=null){
            MainActivity activity = mainActivityWeakRef.get();
            if (activity != null){
                activity.defaultSelectHome();
            }
        }
    }

    public static void setDeviceHandleActivity(DeviceHandleActivity activity){
        deviceHandleActivityRef = new WeakReference<>(activity);
    }

    public static void deviceHandleActivity_flushList(int mode){
        if (deviceHandleActivityRef != null) {
            DeviceHandleActivity activity = deviceHandleActivityRef.get();
            if (activity != null) {
                activity.flushList(mode);
            }
        }
    }
}